package com.example.gulidestudy;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.transition.DrawableCrossFadeFactory;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ImageView iv=findViewById(R.id.iv);

        RequestOptions requestOptions=new RequestOptions()
                .placeholder(R.drawable.hold)
                .error(R.drawable.erro)
                .fallback(R.drawable.ic_baseline_hourglass_empty_24);

        //交叉淡入效果
        DrawableCrossFadeFactory factory=new DrawableCrossFadeFactory.Builder().setCrossFadeEnabled(true).build();

        Glide.with(this)
                .load("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fp02.sfimg.cn%2F2019%2F4400326885%2Foriginal_4400326885_1_1.jpg&refer=http%3A%2F%2Fp02.sfimg.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1628583708&t=d1c4389ca34e39fdef4e366c37799713")
                .apply(requestOptions)
                .transition(DrawableTransitionOptions.withCrossFade(factory))//淡入淡出
                .transform(new CircleCrop())//圆角
                .into(iv);
    }
}